package com.jueling.culture.util;

import java.util.Random;

/**
 * @author liyk
 * @Data 2018/11/16 14:51
 */
public class RandomUtil {

    /**
     * 6位随机数
     * @return
     */
    public static String getRandomCode(){
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for(int i=0;i<6;i++) {
            sb.append(random.nextInt(10));
        }
        return sb.toString();
    }

    /**
     * 指定位数随机数
     * @param codeLength
     * @return
     */
    public static String getRandomCode(Integer codeLength){
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for(int i=0;i<codeLength;i++) {
            sb.append(random.nextInt(10));
        }
        return sb.toString();
    }

    /**
     * 获取十位随机数
     * @return
     */
    public static String getRandomNumber() {
        StringBuffer number = new StringBuffer();
        for (int i=0;i<10;i++){
            number.append((int)(100*(Math.random())%10));
        }
        return number.toString();
    }


}
